# Replication code for Taylor C. Boas (2015), "Voting for Democracy: Campaign Effects in Chile's Democratic Transition," Latin American Politics & Society 57, 2. This article analyzes the survey "Estudio NP55," October 1988, conducted by the Centro de Estudios de la Realidad Contemporánea. The replication file contains only those variables used in the analysis, which I have been given permisson to post online. Anyone interested in gaining access to the full file should contact Carlos Huneeus, Director of CERC, at corpcerc@rdc.cl. The questionnaire is archived at the Harvard Dataverse Network (http://thedata.harvard.edu/dvn/, same location as this file) and is also reproduced in J. L. Piñuel Raigada (1990), "La cultura política del ciudadano y la comunicación política en TV, en la transición política del plebiscito chileno (octubre 1988)," Revista Española de Investigaciones Sociales 50, 90: 125-237.

rm(list=ls(all=T))

# Set working directory as appropriate

setwd('~/Dropbox/Current Research/Voting for Democracy/replication/')

# Load packages

library(Matching)
library(nnet)
library(Hmisc)
library(mvtnorm)
library(ggplot2)
library(foreign)
library(car)

# =====================
# Load replication file
# =====================

# The file contains the following objects:
#
# CERC: Survey data file (only those variables used in the analysis, as noted above).
# polls: Vote intention for plebiscite options, from internal surveys by CIS, used to reproduce Figure 1.
# gen1.12fi, gen1.13fi: Objects of class GenMatch, returned by the function GenMatch() in the Matching package, containing the matches used in the analysis. The code that generated these objects is below but is commented out. One should not expect running the code to reproduce these objects exactly, since (at least at the time the analysis was run) the psuedo-random solution returned by GenMatch() is platform-specific.

load('voting_democracy_replication.RData')

# ==============================================================
# Create new variables for analysis by recoding from survey file
# ==============================================================

religion<-recode(CERC$RELIG,"1='catholic';2:8='evangelical';
    10:11='other';12:13='none';else=NA",as.factor.result=T,
    levels=c('catholic','evangelical','other','none'))
practicing<-recode(CERC$P6,"1='very';2='yes';3='not very';
    4='no';else=NA",as.factor.result=T,levels=c('very',
    'yes','not very','no'))
religious<-4-as.numeric(practicing) # More religious higher
religious[religion=='none']<-0 # No religion = not religious
religious[is.na(religious)]<-mean(religious,na.rm=T) # NA's get mean values

medium<-ifelse(!CERC$P7,NA,CERC$P7)
medium<-factor(medium,labels=c('TV','newspaper','radio',
    'magazines','other','TV/newspaper','TV/radio',
    'TV/newspaper/radio'))
TVinfo<-medium %in% c('TV','TV/newspaper','TV/radio',
    'TV/newspaper/radio')
    
freq.TVnews<-ifelse(!CERC$P141,NA,CERC$P141)
TVnews<-4-as.numeric(freq.TVnews) # Higher is more often
TVnews[is.na(TVnews)]<-mean(TVnews,na.rm=T)

freq.TVmovie<-ifelse(!CERC$P143,NA,CERC$P143)
TVmovie<-4-as.numeric(freq.TVmovie) # Higher is more often
TVmovie[is.na(TVmovie)]<-mean(TVmovie,na.rm=T)

freq.TVsoaps<-ifelse(!CERC$P146,NA,CERC$P146)
TVsoaps<-4-as.numeric(freq.TVsoaps) # Higher is more often
TVsoaps[is.na(TVsoaps)]<-mean(TVsoaps,na.rm=T)

vote.full<-CERC$VOTO
vote.full[!vote.full]<-4
vote.full<-factor(vote.full,labels=c('yes','no',
    'blank/none','no response'))

urban<-CERC$CIU %in% c(11,12,13,19)

police.widow<-ifelse(!CERC$P211,NA,CERC$P211)==1
youth.protest<-ifelse(!CERC$P212,NA,CERC$P212)==2
dark.tunnel<-ifelse(!CERC$P213,NA,CERC$P213)==1
mother.cazzely<-ifelse(!CERC$P215,NA,CERC$P215)==2
yes.correct<-apply(cbind(police.widow,dark.tunnel),1,sum,na.rm=T)
no.correct<-apply(cbind(youth.protest,mother.cazzely),1,sum,na.rm=T)
reception<-(yes.correct > no.correct) +
            2 * (no.correct > yes.correct) +
            3 * (yes.correct + no.correct == 4) +
            4 * (yes.correct == 1 & no.correct == 1)
reception<-factor(reception,labels=c('None','Yes','No','Both','Half'))

educ<-ifelse(!CERC$REDUC,NA,CERC$REDUC)
educ<-factor(educ,labels=c('none','some primary',
    'primary','some secondary','secondary','some college',
    'college'))
education<-7-as.numeric(educ) # Higher is more education
education[is.na(educ)]<-mean(education,na.rm=T)

sex<-factor(CERC$SEXO,labels=c('male','female'))
male<-sex=='male' 

age<-CERC$EDAD

income<-ifelse(CERC$INGRE %in% c(0,10),NA,CERC$INGRE)
income[is.na(income)]<-mean(income,na.rm=T)

student<-CERC$SOCUP==8|CERC$OCUPRE==4
housewife<-CERC$OCUPRE==1&CERC$SOCUP!=8
unemployed<-CERC$SOCUP==(CERC$SOCUP==3&CERC$OCUPRE %in% c(5,25,99)|
    CERC$SOCUP==7&CERC$OCUPRE==99)
retired<-CERC$SOCUP %in% 5:6|CERC$OCUPRE==3
indep.wealth<-CERC$SOCUP==4&CERC$OCUPRE==5
worker<-(CERC$OCUPRE %in% 6:11)&!student
whitecol<-CERC$OCUPRE %in% 12:17
military<-CERC$OCUPRE %in% 18:19
professional<-CERC$OCUPRE %in% 20:21
farmer<-CERC$OCUPRE %in% 22:23
otherjob<-(CERC$OCUPRE %in% c(0,24,49,99)&CERC$SOCUP==1)|
    (CERC$OCUPRE==99&CERC$SOCUP==2)

works<-worker|whitecol|military|professional|farmer|otherjob

R1<-CERC$CIU %in% 1:2
R2<-CERC$CIU %in% 3:4
R3<-CERC$CIU == 5
R4<-CERC$CIU %in% 6:7
R5<-CERC$CIU %in% 8:12
RM<-CERC$CIU == 13
R6<-CERC$CIU == 14
R7<-CERC$CIU %in% 15:16
R8<-CERC$CIU %in% 17:22
R9<-CERC$CIU == 23
R10<-CERC$CIU %in% 24:26

woman.home<-ifelse(!CERC$P481,NA,CERC$P481)
woman.home<-ifelse(is.na(woman.home),mean(woman.home,
    na.rm=T),woman.home)
woman.kids<-ifelse(!CERC$P482,NA,CERC$P482)
woman.kids<-ifelse(is.na(woman.kids),mean(woman.kids,
    na.rm=T),woman.kids)

opp.paper<-CERC$P8 %in% c(2,5)
opp.radio<-CERC$P10==2
UCTV<-CERC$P12==4
TVN<-CERC$P12==2

final.data<-data.frame(no.correct,yes.correct,reception,education,income,age,religious,male,works,urban,TVnews,TVinfo,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,opp.paper,opp.radio,UCTV,TVN,TVsoaps,TVmovie,vote.full,woman.home,woman.kids)

# ===================================================
# Figure 1. Vote Intention in Chile’s 1988 Plebiscite
# ===================================================

tiff("polls.tiff", height = 1200, width  = 1500, units='px', res=300, compression='none')
par(mar=c(4,4,1,1)+0.1)
plot(polls$Date[-1],polls$Yes[-1],type='l',ylim=c(0,60),
	ylab="Percent", xlab='1988', lwd=2, lty=2, col='blue')
lines(polls$Date[-1],polls$No[-1], lwd=2, lty=1, col='red')
lines(polls$Date[-1],polls$DK.NR.Blank[-1], lwd=2, lty=4)
abline(v= as.Date("1988-9-5"),lwd=2,lty=3)
text(as.Date("1988-7-1"),21.5,"Yes", col='blue')
text(as.Date("1988-6-15"),36,"No", col='red')
text(as.Date("1988-7-7"),52,"Uncommitted")
text(as.Date("1988-8-26"),9,"Franja\nbegins",srt=90)
dev.off()

# =====================================================
# Table 2. Balance Statistics Before and After Matching
# =====================================================

CERC.Tr12<-final.data[final.data$reception %in% c('Yes','No'),]
CERC.Tr13<-final.data[final.data$reception %in% c('Yes','Both'),]

Tr12<-CERC.Tr12$reception=='Yes'
CERC.Tr12<-cbind(Tr12,CERC.Tr12)
Tr13<-CERC.Tr13$reception=='Yes'
CERC.Tr13<-cbind(Tr13,CERC.Tr13)

pTr12<-glm(Tr12~ education + I(education^2) + income +
    I(income^2) + age + I(age^2) + religious + 
    I(religious^2) + male + works + TVnews + I(TVnews^2) +
    TVinfo + opp.paper + opp.radio + UCTV + R1 + R2 + R3
    + R4 + R5 + R6 + R7 + R8 + R9 + R10 +
    TVN + urban, family=binomial, data=CERC.Tr12)

pTr13<-glm(Tr13~ education + I(education^2) + income +
    I(income^2) + age + I(age^2) + religious + 
    I(religious^2) + male + works + TVnews + I(TVnews^2) +
    TVinfo + opp.paper + opp.radio + UCTV + R1 + R2 + R3
    + R4 + R5 + R6 + R7 + R8 + R9 + R10 +
    TVN + urban, family=binomial, data=CERC.Tr13)

X12<-cbind(pTr12$linear.predictors,CERC.Tr12[,c('education',
    'income','age','religious','male','works','urban',
    'TVnews','TVinfo','R1','R2','R3','R4','R5','R6','R7',
    'R8','R9','R10','opp.paper','opp.radio','UCTV','TVN')])

X13<-cbind(pTr13$linear.predictors,CERC.Tr13[,c('education',
    'income','age','religious','male','works','urban',
    'TVnews','TVinfo','R1','R2','R3','R4','R5','R6','R7',
    'R8','R9','R10','opp.paper','opp.radio','UCTV','TVN')])

BM12<-cbind(X12,X12$education^2,X12$income^2,X12$age^2,
    X12$religious^2,X12$TVnews^2,X12$male*X12$TVN,
    X12$opp.paper*X12$TVN,X12$TVinfo*X12$opp.paper,
    X12$works*X12$opp.radio,X12$works*X12$TVN,
    X12$education*X12$urban,X12$male*X12$income,
    X12$income*X12$UCTV,X12$age*X12$male,X12$TVinfo*X12$TVN,
    X12$opp.paper*X12$UCTV,X12$urban*X12$TVnews,
    X12$male*X12$opp.paper,X12$education*X12$age)

BM13<-cbind(X13,X13$education^2,X13$income^2,X13$age^2,
    X13$religious^2,X13$TVnews^2,X13$education*X13$religious,
    X13$age*X13$works,X13$male*X13$works,X13$works*X13$TVinfo,
    X13$urban*X13$opp.paper,X13$urban*X13$opp.radio,
    X13$religious*X13$opp.paper,X13$works*X13$TVnews,
    X13$TVnews*X13$TVN,X13$TVinfo*X13$opp.radio,X13$TVinfo*
    X13$TVN,X13$education*X13$male,X13$income*X13$male,
    X13$income*X13$opp.radio,X13$age*X13$male,X13$urban*
    X13$TVN,X13$age*X13$opp.paper,X13$religious*X13$male,
    X13$male*X13$urban,X13$male*X13$TVnews,X13$male*X13$TVN,
    X13$opp.radio*X13$TVN,X13$religious*X13$TVN,X13$TVnews*
    X13$opp.paper,X13$income*X13$UCTV)

# The two lines below generate the matches, contained in the objects gen1.12fi and gen1.13fi. These objects have already been loaded as part of the replication file. Uncomment these lines to regenerate them from scratch. See note, above, under "Load replication file."
    
#gen1.12fi<-GenMatch(Tr=Tr12,X=X12,BalanceMatrix=BM12,pop.size=1000)
#gen1.13fi<-GenMatch(Tr=Tr13,X=X13,BalanceMatrix=BM13,pop.size=1000)

mgen1.12fi<-Match(Tr=Tr12,X=X12,Weight.matrix=gen1.12fi)
mgen1.13fi<-Match(Tr=Tr13,X=X13,Weight.matrix=gen1.13fi)

balance.12<-MatchBalance(Tr12~education + I(education^2) + income +
    I(income^2) + age + I(age^2) + religious + 
    I(religious^2) + male + works + urban + 
    TVnews + I(TVnews^2) + TVinfo + R1 + R2 + R3 + R4 +
    R5 + R6 + R7 + R8 + R9 + R10 + opp.paper + opp.radio +
    UCTV + TVN + woman.home + woman.kids, match.out=mgen1.12fi, nboots=1000, data=CERC.Tr12)

balance.13<-MatchBalance(Tr13~education + I(education^2) + income +
    I(income^2) + age + I(age^2) + religious + 
    I(religious^2) + male + works + urban + 
    TVnews + I(TVnews^2) + TVinfo + R1 + R2 + R3 + R4 +
    R5 + R6 + R7 + R8 + R9 + R10 + opp.paper + opp.radio +
    UCTV + TVN + woman.home + woman.kids, match.out=mgen1.13fi, nboots=1000, data=CERC.Tr13)

min.pval.no.before<-sapply(balance.12$BeforeMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})
min.pval.no.after<-sapply(balance.12$AfterMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})
min.pval.both.before<-sapply(balance.13$BeforeMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})
min.pval.both.after<-sapply(balance.13$AfterMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})

sdiff.no.before<-sapply(balance.12$BeforeMatching,function(x) x$sdiff)
sdiff.no.after<-sapply(balance.12$AfterMatching,function(x) x$sdiff)
sdiff.both.before<-sapply(balance.13$BeforeMatching,function(x) x$sdiff)
sdiff.both.after<-sapply(balance.13$AfterMatching,function(x) x$sdiff)

balance.table<-round(data.frame(sdiff.no.before,sdiff.no.after,min.pval.no.before,min.pval.no.after,sdiff.both.before,sdiff.both.after,min.pval.both.before,min.pval.both.after),2)
	
bottom.note.balance<-paste("Note: Standardized mean difference is 100 times the mean difference of the treated and control observations divided by the standard deviation of the treated observations. Minimium p-values are from bootstrapped Kolmogorov-Smirnov (KS) tests or mean difference t-tests (two-sample before matching, paired after matching). Chile's Regions 11-–12 were not sampled by the survey. Urban is an indicator variable for residing in Santiago, Valpara\\'iso, Vi\\~na del Mar, or Concepci\\'on.")

balance.table.latex<-latex(balance.table,file='balance_table.tex',collabel.just=rep('r',8),col.just = rep('r',8),rowname=c("Education","Education$^2$","Income","Income$^2$","Age","Age$^2$","Religiosity","Religiosity$^2$","Male","Employed","Urban","TVnews","TVnews$^2$","TVinfo","Region 1","Region 2","Region 3","Region 4","Region 5","Region 6","Region 7","Region 8","Region 9","Region 10","Opp.\\ Paper","Opp.\\ Radio","UCTV","TVN","Woman-Home","Woman-Kids"),rowlabel='',colheads=rep(c("StdDiff","StdDiff","MinPval","MinPval"),2),extracolheads=rep(c("Before","After"),4),extracolsize="normalsize",caption = 'Balance Statistics Before and After Matching',insert.bottom=bottom.note.balance,booktabs = F, ctable = T, where = "htp",cgroup=c("Yes vs.\\ No", "Yes vs.\\ Both"),n.cgroup=c(4,4),rgroup=c('Variable','Placebo Tests'),n.rgroup=c(28,2))

# ========================================
# Table 3. Campaign Effects on Vote Choice
# ========================================

data.match<-rbind(CERC.Tr12[mgen1.12fi$index.treated,-1],
    CERC.Tr12[mgen1.12fi$index.control,-1],
    CERC.Tr13[mgen1.13fi$index.control,-1])

Y12.na<-CERC.Tr12$vote.full=='no response'
Y13.na<-CERC.Tr13$vote.full=='no response'
match12.na<-Match(Y=Y12.na,Tr=Tr12,X=X12,Weight.matrix=gen1.12fi)
match13.na<-Match(Y=Y13.na,Tr=Tr13,X=X13,Weight.matrix=gen1.13fi)

Y12.no<-CERC.Tr12$vote.full=='no'
Y13.no<-CERC.Tr13$vote.full=='no'
match12.no<-Match(Y=Y12.no,Tr=Tr12,X=X12,Weight.matrix=gen1.12fi)
match13.no<-Match(Y=Y13.no,Tr=Tr13,X=X13,Weight.matrix=gen1.13fi)

Y12.yes<-CERC.Tr12$vote.full=='yes'
Y13.yes<-CERC.Tr13$vote.full=='yes'
match12.yes<-Match(Y=Y12.yes,Tr=Tr12,X=X12,Weight.matrix=gen1.12fi)
match13.yes<-Match(Y=Y13.yes,Tr=Tr13,X=X13,Weight.matrix=gen1.13fi)

Y12.bl<-CERC.Tr12$vote.full=='blank/none'
Y13.bl<-CERC.Tr13$vote.full=='blank/none'
match12.bl<-Match(Y=Y12.bl,Tr=Tr12,X=X12,Weight.matrix=gen1.12fi)
match13.bl<-Match(Y=Y13.bl,Tr=Tr13,X=X13,Weight.matrix=gen1.13fi)

diff.na<-t.test(Y13.na[mgen1.13fi$index.control], Y12.na[mgen1.12fi$index.control],var.equal=T)
diff.no<-t.test(Y13.no[mgen1.13fi$index.control], Y12.no[mgen1.12fi$index.control],var.equal=T)
diff.yes<-t.test(Y13.yes[mgen1.13fi$index.control], Y12.yes[mgen1.12fi$index.control],var.equal=T)
diff.bl<-t.test(Y13.bl[mgen1.13fi$index.control], Y12.bl[mgen1.12fi$index.control],var.equal=T)

att.est<-rbind(c(match12.no$est,match12.yes$est,match12.bl$est,match12.na$est),
	c(match13.no$est,match13.yes$est,match13.bl$est,match13.na$est),
	c(diff.no$estimate[1]-diff.no$estimate[2],diff.yes$estimate[1]-diff.yes$estimate[2],diff.bl$estimate[1]-diff.bl$estimate[2],diff.na$estimate[1]-diff.na$estimate[2]))
att.est[1:2,]<- -1*att.est[1:2,] # Reporting negative of ATT, as explained in article text. Does not affect third row, difference in ATTs.
att.se<-rbind(c(match12.no$se.standard,match12.yes$se.standard,match12.bl$se.standard,match12.na$se.standard),
	c(match13.no$se.standard,match13.yes$se.standard,match13.bl$se.standard,match13.na$se.standard),
	c(diff.no$estimate[1]-diff.no$estimate[2],diff.yes$estimate[1]-diff.yes$estimate[2],diff.bl$estimate[1]-diff.bl$estimate[2],diff.na$estimate[1]-diff.na$estimate[2])/c(diff.no$statistic,diff.yes$statistic,diff.bl$statistic,diff.na$statistic))

att.stars<-matrix('',nrow=nrow(att.est),ncol=ncol(att.est))
att.stars[2*(1-pt(abs(att.est/att.se),nrow(data.match)*2/3-2))<.1]<-'$\\dagger$'
att.stars[2*(1-pt(abs(att.est/att.se),nrow(data.match)*2/3-2))<.05]<-'*'
att.stars[2*(1-pt(abs(att.est/att.se),nrow(data.match)*2/3-2))<.01]<-'**'
att.stars[2*(1-pt(abs(att.est/att.se),nrow(data.match)*2/3-2))<.001]<-'***'

att.spacer<-ifelse(round(att.est,2)<0,'','\\ ')

att.est<-matrix(paste(att.spacer,round(att.est,2),att.stars,sep=''),nrow=nrow(att.est))
att.se<-matrix(paste('(',round(att.se,2),')',sep=''),nrow=nrow(att.se))

# ATTs with post-matching multinomial logit

data.match$reception<-data.match$reception[, drop=T]
data.match$nomsg<-data.match$reception=='No'
data.match$bothmsg<-data.match$reception=='Both'

# NOTE: dropping the regional fixed effects here because of singularities

mod.match<-multinom(vote.full~ nomsg + bothmsg + education +
    I(education^2) + income + I(income^2) + age + I(age^2) +
    religious + I(religious^2) + male + works + urban + 
    TVnews + I(TVnews^2) + TVinfo +  opp.paper + opp.radio +
    UCTV + TVN, data=data.match, Hess=T)

sim.bhat<-rmvnorm(1000,mean=as.vector(t(summary(mod.match)$coefficients)),sigma=solve(mod.match$Hess),method='chol')
x<-cbind(1, data.match$nomsg, data.match$bothmsg, data.match$education, I(data.match$education^2), data.match$income, I(data.match$income^2), data.match$age, I(data.match$age^2), data.match$religious, I(data.match$religious^2), data.match$male, data.match$works, data.match$urban, data.match$TVnews, I(data.match$TVnews^2), data.match$TVinfo, data.match$opp.paper, data.match$opp.radio, data.match$UCTV, data.match$TVN)

pno<-exp(x%*%t(sim.bhat[,1:21]))/(1+exp(x%*%t(sim.bhat[,1:21]))+exp(x%*%t(sim.bhat[,22:42]))+exp(x%*%t(sim.bhat[,43:63])))
pyes<-1/(1+exp(x%*%t(sim.bhat[,1:21]))+exp(x%*%t(sim.bhat[,22:42]))+exp(x%*%t(sim.bhat[,43:63])))
pbl<-exp(x%*%t(sim.bhat[,22:42]))/(1+exp(x%*%t(sim.bhat[,1:21]))+exp(x%*%t(sim.bhat[,22:42]))+exp(x%*%t(sim.bhat[,43:63])))
pnr<-exp(x%*%t(sim.bhat[,43:63]))/(1+exp(x%*%t(sim.bhat[,1:21]))+exp(x%*%t(sim.bhat[,22:42]))+exp(x%*%t(sim.bhat[,43:63])))

atts<-data.frame(
	pno=c(mean(apply(pno[data.match$reception=='Yes',],2,mean)-apply(pno[data.match$reception=='No',],2,mean)),
		mean(apply(pno[data.match$reception=='Yes',],2,mean)-apply(pno[data.match$reception=='Both',],2,mean))),
	pyes=c(mean(apply(pyes[data.match$reception=='Yes',],2,mean)-apply(pyes[data.match$reception=='No',],2,mean)),
		mean(apply(pyes[data.match$reception=='Yes',],2,mean)-apply(pyes[data.match$reception=='Both',],2,mean))),
	pbl=c(mean(apply(pbl[data.match$reception=='Yes',],2,mean)-apply(pbl[data.match$reception=='No',],2,mean)),
		mean(apply(pbl[data.match$reception=='Yes',],2,mean)-apply(pbl[data.match$reception=='Both',],2,mean))),
	pnr=c(mean(apply(pnr[data.match$reception=='Yes',],2,mean)-apply(pnr[data.match$reception=='No',],2,mean)),
		mean(apply(pnr[data.match$reception=='Yes',],2,mean)-apply(pnr[data.match$reception=='Both',],2,mean))))
atts<- -1*atts # Reporting negative of ATT, as explained in article text

att.ses<-data.frame(
	pno=c(sd(apply(pno[data.match$reception=='Yes',],2,mean)-apply(pno[data.match$reception=='No',],2,mean)),
		sd(apply(pno[data.match$reception=='Yes',],2,mean)-apply(pno[data.match$reception=='Both',],2,mean))),
	pyes=c(sd(apply(pyes[data.match$reception=='Yes',],2,mean)-apply(pyes[data.match$reception=='No',],2,mean)),
		sd(apply(pyes[data.match$reception=='Yes',],2,mean)-apply(pyes[data.match$reception=='Both',],2,mean))),
	pbl=c(sd(apply(pbl[data.match$reception=='Yes',],2,mean)-apply(pbl[data.match$reception=='No',],2,mean)),
		sd(apply(pbl[data.match$reception=='Yes',],2,mean)-apply(pbl[data.match$reception=='Both',],2,mean))),
	pnr=c(sd(apply(pnr[data.match$reception=='Yes',],2,mean)-apply(pnr[data.match$reception=='No',],2,mean)),
		sd(apply(pnr[data.match$reception=='Yes',],2,mean)-apply(pnr[data.match$reception=='Both',],2,mean))))

diff.atts<-data.frame(
	pno=mean(apply(pno[data.match$reception=='Both',],2,mean)-apply(pno[data.match$reception=='No',],2,mean)),
	pyes=mean(apply(pyes[data.match$reception=='Both',],2,mean)-apply(pyes[data.match$reception=='No',],2,mean)),
	pbl=mean(apply(pbl[data.match$reception=='Both',],2,mean)-apply(pbl[data.match$reception=='No',],2,mean)),
	pnr=mean(apply(pnr[data.match$reception=='Both',],2,mean)-apply(pnr[data.match$reception=='No',],2,mean)))
	
diff.atts.se<-data.frame(
	pno=sd(apply(pno[data.match$reception=='Both',],2,mean)-apply(pno[data.match$reception=='No',],2,mean)),
	pyes=sd(apply(pyes[data.match$reception=='Both',],2,mean)-apply(pyes[data.match$reception=='No',],2,mean)),
	pbl=sd(apply(pbl[data.match$reception=='Both',],2,mean)-apply(pbl[data.match$reception=='No',],2,mean)),
	pnr=sd(apply(pnr[data.match$reception=='Both',],2,mean)-apply(pnr[data.match$reception=='No',],2,mean)))

att.mnl.est<-as.matrix(rbind(atts,diff.atts))
att.mnl.se<-as.matrix(rbind(att.ses,diff.atts.se))

att.mnl.stars<-matrix('',nrow=nrow(att.mnl.est),ncol=ncol(att.mnl.est))
att.mnl.stars[2*(1-pnorm(abs(att.mnl.est/att.mnl.se)))<.1]<-'$\\dagger$'
att.mnl.stars[2*(1-pnorm(abs(att.mnl.est/att.mnl.se)))<.05]<-'*'
att.mnl.stars[2*(1-pnorm(abs(att.mnl.est/att.mnl.se)))<.01]<-'**'
att.mnl.stars[2*(1-pnorm(abs(att.mnl.est/att.mnl.se)))<.001]<-'***'

att.mnl.spacer<-ifelse(round(att.mnl.est,2)<0,'','\\ ')

att.mnl.est<-matrix(paste(att.mnl.spacer,round(att.mnl.est,2),att.mnl.stars,sep=''),nrow=nrow(att.mnl.est))
att.mnl.se<-matrix(paste('(',round(att.mnl.se,2),')',sep=''),nrow=nrow(att.mnl.se))

# Generate table

match.table<-matrix(rbind(as.vector(cbind(att.est,att.mnl.est)),as.vector(cbind(att.se,att.mnl.se))),ncol=ncol(cbind(att.est,att.mnl.est)))
	
bottom.note.match<-paste('N = 316 for each comparison. $\\dagger p < .1$, *$p < .05$, **$p < .01$. Note: The no message reception group answered more questions correctly about the advertising ofthe no campaign than that of the yes campaign; the opposite is true of the yes group. The both group answered two questions correctly about each. The message reception group comparison column specifies pairwise comparisons of these groups. Table entries are mean differences in the proportion voting for each plebiscite option, with estimated standard errors in parentheses. Regression-adjusted mean differences are based on predicted probabilities from a multinomial logistic model. Standard errors for the regression-adjusted estimates are based on a simulation in which one thousand sets of coefficient estimates were drawn at random from a multivariate normal distribution with mean and variance-covariance matrix as estimated in this model.')

match.table.latex<-latex(match.table,file='match_table.tex',collabel.just=rep('l',8),col.just = rep('l',8),rowname=c("No -- Yes","","Both -- Yes","","Both -- No",""),rowlabel='',colheads=rep(c("\nNo","\nYes","Blank/\nNone","\nNR"),2),rgroup='Group Comparison',n.rgroup=6,caption = 'Campaign Effects on Vote Choice',insert.bottom=bottom.note.match,booktabs = F, ctable = T, where = "htp",extracolsize="normalsize",cgroup=c('Vote (Unadjusted)','Vote (Regression-Adjusted)'),n.cgroup=c(4,4))

# ===========================================
# Appendix Table 1. Balance Statistics for
# Interaction Terms Before and After Matching
# ===========================================

X12.noreg<-X12[,!(names(X12) %in% c('R1','R2','R3','R4',
    'R5','R6','R7','R8','R9','R10'))]
X13.noreg<-X13[,!(names(X13) %in% c('R1','R2','R3','R4',
    'R5','R6','R7','R8','R9','R10'))]

X12.int<-NA
for(i in 2:(ncol(X12.noreg)-1)){
    for(j in (i+1):ncol(X12.noreg)) {
        X12.int<-cbind(X12.int,X12.noreg[,i]*X12.noreg[,j])
        colnames(X12.int)[ncol(X12.int)]<-
            paste(colnames(X12.noreg)[i],'*',
            colnames(X12.noreg)[j])
    }
}
X12.int<-X12.int[,-1]
X12.int<-X12.int[,-1*grep('opp.paper \\* TVN|opp.radio \\* TVN|UCTV \\* TVN',colnames(X12.int))]

balance.12.int<-MatchBalance(Tr12~ X12.int, match.out=mgen1.12fi, nboots=1000)

X13.int<-NA
for(i in 2:(ncol(X13.noreg)-1)){
    for(j in (i+1):ncol(X13.noreg)) {
        X13.int<-cbind(X13.int,X13.noreg[,i]*X13.noreg[,j])
        colnames(X13.int)[ncol(X13.int)]<-
            paste(colnames(X13.noreg)[i],'*',
            colnames(X13.noreg)[j])
    }
}
X13.int<-X13.int[,-1]
X13.int<-X13.int[,-1*grep('opp.paper \\* TVN|opp.radio \\* TVN|UCTV \\* TVN',colnames(X13.int))]

balance.13.int<-MatchBalance(Tr13~ X13.int, match.out=mgen1.13fi, nboots=1000)

min.pval.no.before.int<-sapply(balance.12.int$BeforeMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})
min.pval.no.after.int<-sapply(balance.12.int$AfterMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})
min.pval.both.before.int<-sapply(balance.13.int$BeforeMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})
min.pval.both.after.int<-sapply(balance.13.int$AfterMatching,function(x){min(x$ks$ks.boot.pvalue,x$tt$p.value)})

sdiff.no.before.int<-sapply(balance.12.int$BeforeMatching,function(x) x$sdiff)
sdiff.no.after.int<-sapply(balance.12.int$AfterMatching,function(x) x$sdiff)
sdiff.both.before.int<-sapply(balance.13.int$BeforeMatching,function(x) x$sdiff)
sdiff.both.after.int<-sapply(balance.13.int$AfterMatching,function(x) x$sdiff)

simpleCap <- function(x) {
  s <- strsplit(x, " ")[[1]]
  paste(toupper(substring(s, 1,1)), substring(s, 2),
      sep="", collapse=" ")
}

varname<-sapply(colnames(X12.int),simpleCap)
names(varname)<-NULL
varname<-gsub('Income','Family Income',varname)
varname<-gsub('Religious','Religiosity',varname)
varname<-gsub('Works','Employed',varname)
varname<-gsub('Opp.paper','Opposition Paper',varname)
varname<-gsub('Opp.radio','Opposition Radio',varname)
varname<-gsub('\\*','$\\\\times$',varname)

balance.table.int<-cbind(varname,round(data.frame(sdiff.no.before.int,sdiff.no.after.int,min.pval.no.before.int,min.pval.no.after.int,sdiff.both.before.int,sdiff.both.after.int,min.pval.both.before.int,min.pval.both.after.int),2))

# LaTeX version of table created manually in .tex file, pasting in the following:
write.table(balance.table.int,file='interaction_balance.txt',sep='&',eol=' \\\\\n',row.names=F,col.names=F,quote=F) 

# =================================================
# Appendix Table 2. Non-Response Simulation Results
# =================================================

# Note: in the code below, unique() is applied wherever
# index.control appears, because the matching with
# replacement used some controls more than once. They will
# be matched the same number of times in the simulation,
# so results shouldn't change, but their vote should be
# changed only once.

num.na.nomsg<-sum(Y12.na[unique(mgen1.12fi$index.control)])
num.na.yesmsg<-sum(Y12.na[mgen1.12fi$index.treated])
num.na.both<-sum(Y13.na[unique(mgen1.13fi$index.control)])

num.no.nomsg<-sum(Y12.no[unique(mgen1.12fi$index.control)])
num.no.yesmsg<-sum(Y12.no[mgen1.12fi$index.treated])
num.no.both<-sum(Y13.no[unique(mgen1.13fi$index.control)])

num.yes.nomsg<-sum(Y12.yes[unique(mgen1.12fi$index.control)])
num.yes.yesmsg<-sum(Y12.yes[mgen1.12fi$index.treated])
num.yes.both<-sum(Y13.yes[unique(mgen1.13fi$index.control)])

r<- c(1/(30:10/10),11:30/10)

a.yesmsg<- -r*(num.yes.yesmsg+num.no.yesmsg+num.na.yesmsg)
b.yesmsg<- (num.no.yesmsg+r*num.yes.yesmsg+(1+r)*num.na.yesmsg)
c.yesmsg<- -num.na.yesmsg

a.nomsg<- -r*(num.yes.nomsg+num.no.nomsg+num.na.nomsg)
b.nomsg<- (num.no.nomsg+r*num.yes.nomsg+(1+r)*num.na.nomsg)
c.nomsg<- -num.na.nomsg

a.both<- -r*(num.yes.both+num.no.both+num.na.both)
b.both<- (num.no.both+r*num.yes.both+(1+r)*num.na.both)
c.both<- -num.na.both

p.yesmsg<-(-b.yesmsg+sqrt(b.yesmsg^2-4*a.yesmsg*c.yesmsg))/
    (2*a.yesmsg)
p.nomsg<-(-b.nomsg+sqrt(b.nomsg^2-4*a.nomsg*c.nomsg))/
    (2*a.nomsg)
p.both<-(-b.both+sqrt(b.both^2-4*a.both*c.both))/
    (2*a.both)

# Simulation of changing NAs

avg.ATT12no.sens<-rep(NA,length(r))
avg.AIse12no.sens<-rep(NA,length(r))
avg.ATT12yes.sens<-rep(NA,length(r))
avg.AIse12yes.sens<-rep(NA,length(r))
avg.ATT13no.sens<-rep(NA,length(r))
avg.AIse13no.sens<-rep(NA,length(r))
avg.ATT13yes.sens<-rep(NA,length(r))
avg.AIse13yes.sens<-rep(NA,length(r))
avg.diff.sens.yes<-rep(NA,length(r))
avg.tdiff.sens.yes<-rep(NA,length(r))
avg.diff.sens.no<-rep(NA,length(r))
avg.tdiff.sens.no<-rep(NA,length(r))
avg.num.yesmsg12.yesvote<-rep(NA,length(r))
avg.num.yesmsg12.novote<-rep(NA,length(r))
avg.num.nomsg.yesvote<-rep(NA,length(r))
avg.num.nomsg.novote<-rep(NA,length(r))
avg.num.yesmsg13.yesvote<-rep(NA,length(r))
avg.num.yesmsg13.novote<-rep(NA,length(r))
avg.num.both.yesvote<-rep(NA,length(r))
avg.num.both.novote<-rep(NA,length(r))
    
nreps<-500

for (t in 1:nreps) {
Y12sens.no<-matrix(rep(Y12.no,length(r)),ncol=length(r))
Y12sens.yes<-matrix(rep(Y12.yes,length(r)),ncol=length(r))
Y13sens.no<-matrix(rep(Y13.no,length(r)),ncol=length(r))
Y13sens.yes<-matrix(rep(Y13.yes,length(r)),ncol=length(r))


for (i in 1:length(r)) {
    num.nomsg.change<-round(num.no.nomsg*p.nomsg[i]/
        (1-p.nomsg[i]))
    num.yesmsg.change<-round(num.no.yesmsg*p.yesmsg[i]/
        (1-p.yesmsg[i]))
    changetono.nomsg<-sample(c(rep(T,num.nomsg.change),
        rep(F,num.na.nomsg - num.nomsg.change)))
    changetono.yesmsg<-sample(c(rep(T,num.yesmsg.change),
        rep(F,num.na.yesmsg - num.yesmsg.change)))
    k<-0
    l<-0
    for (j in unique(mgen1.12fi$index.control)) {
        if (Y12.na[j]) { # NA vote, No msg
            k<-k+1
            Y12sens.no[j,i]<-changetono.nomsg[k]
            Y12sens.yes[j,i]<-!(changetono.nomsg[k])
        }
    }
    for (j in mgen1.12fi$index.treated) {        
        if (Y12.na[j]) { # NA vote, Yes msg
            l<-l+1
            Y12sens.no[j,i]<-changetono.yesmsg[l]
            Y12sens.yes[j,i]<-!(changetono.yesmsg[l])
        }    
    }
}

for (i in 1:length(r)) {
    num.both.change<-round(num.no.both*p.both[i]/
        (1-p.both[i]))
    num.yesmsg.change<-round(num.no.yesmsg*p.yesmsg[i]/
        (1-p.yesmsg[i]))
    changetono.both<-sample(c(rep(T,num.both.change),
        rep(F,num.na.both - num.both.change)))
    changetono.yesmsg<-sample(c(rep(T,num.yesmsg.change),
        rep(F,num.na.yesmsg - num.yesmsg.change)))
    k<-0
    l<-0
    for (j in unique(mgen1.13fi$index.control)) {
        if (Y13.na[j]) { # NA vote, No msg
            k<-k+1
            Y13sens.no[j,i]<-changetono.both[k]
            Y13sens.yes[j,i]<-!(changetono.both[k])
        }
    }
    for (j in mgen1.13fi$index.treated) {        
        if (Y13.na[j]) { # NA vote, Yes msg
            l<-l+1
            Y13sens.no[j,i]<-changetono.yesmsg[l]
            Y13sens.yes[j,i]<-!(changetono.yesmsg[l])
        }    
    }
}

# Matching

match12no.sens<-apply(Y12sens.no, 2,
    function(Y) { Match(Y=Y,Tr=Tr12,X=X12,Weight.matrix=gen1.12fi) } )
match12yes.sens<-apply(Y12sens.yes, 2,
    function(Y) { Match(Y=Y,Tr=Tr12,X=X12,Weight.matrix=gen1.12fi) } )
match13no.sens<-apply(Y13sens.no, 2, 
    function(Y) { Match(Y=Y,Tr=Tr13,X=X13,Weight.matrix=gen1.13fi) } )
match13yes.sens<-apply(Y13sens.yes, 2,
    function(Y) { Match(Y=Y,Tr=Tr13,X=X13,Weight.matrix=gen1.13fi) } )

ATT12no.sens<-sapply(match12no.sens,function(Y) { Y$est } )
AIse12no.sens<-sapply(match12no.sens,function(Y) { Y$se.standard } )
ATT12yes.sens<-sapply(match12yes.sens,function(Y) { Y$est } )
AIse12yes.sens<-sapply(match12yes.sens,function(Y) { Y$se.standard } )
ATT13no.sens<-sapply(match13no.sens,function(Y) { Y$est } )
AIse13no.sens<-sapply(match13no.sens,function(Y) { Y$se.standard } )
ATT13yes.sens<-sapply(match13yes.sens,function(Y) { Y$est } )
AIse13yes.sens<-sapply(match13yes.sens,function(Y) { Y$se.standard } )

# Counts in each category

num.yesmsg12.yesvote<-apply(Y12sens.yes[mgen1.12fi$index.treated,],
    2,sum)
num.yesmsg12.novote<-apply(Y12sens.no[mgen1.12fi$index.treated,],
    2,sum)
num.nomsg.yesvote<-apply(Y12sens.yes[mgen1.12fi$index.control,],
    2,sum)
num.nomsg.novote<-apply(Y12sens.no[mgen1.12fi$index.control,],
    2,sum)
num.yesmsg13.yesvote<-apply(Y13sens.yes[mgen1.13fi$index.treated,],
    2,sum)
num.yesmsg13.novote<-apply(Y13sens.no[mgen1.13fi$index.treated,],
    2,sum)
num.both.yesvote<-apply(Y13sens.yes[mgen1.13fi$index.control,],
    2,sum)
num.both.novote<-apply(Y13sens.no[mgen1.13fi$index.control,],
    2,sum)
    
# Difference in differences tests

TT12sens.yes<-Y12sens.yes[mgen1.12fi$index.treated,]-
    Y12sens.yes[mgen1.12fi$index.control,]
TT12sens.no<-Y12sens.no[mgen1.12fi$index.treated,]-
    Y12sens.no[mgen1.12fi$index.control,]
TT13sens.yes<-Y13sens.yes[mgen1.13fi$index.treated,]-
    Y13sens.yes[mgen1.13fi$index.control,]
TT13sens.no<-Y13sens.no[mgen1.13fi$index.treated,]-
    Y13sens.no[mgen1.13fi$index.control,]

tdiff.sens.yes<-NA
diff.sens.yes<-NA 
for (i in 1:length(r)) {
    tdiff.sens.yes[i]<-t.test(Y13sens.yes[mgen1.13fi$index.control,i],Y12sens.yes[mgen1.12fi$index.control,i],var.equal=T)$statistic
    diff.sens.yes[i]<-as.numeric(-1*diff(t.test(Y13sens.yes[mgen1.13fi$index.control,i],Y12sens.yes[mgen1.12fi$index.control,i],var.equal=T)$estimate))
}

tdiff.sens.no<-NA
diff.sens.no<-NA 
for (i in 1:length(r)) {
    tdiff.sens.no[i]<-t.test(Y13sens.no[mgen1.13fi$index.control,i],Y12sens.no[mgen1.12fi$index.control,i],var.equal=T)$statistic
    diff.sens.no[i]<-as.numeric(-1*diff(t.test(Y13sens.no[mgen1.13fi$index.control,i],Y12sens.no[mgen1.12fi$index.control,i],var.equal=T)$estimate))
}
    
# Running averages

avg.ATT12no.sens<-apply(cbind(matrix(rep(avg.ATT12no.sens,
    t-1),nrow=length(r)),ATT12no.sens),1,mean,na.rm=T)
avg.AIse12no.sens<-apply(cbind(matrix(rep(avg.AIse12no.sens,
    t-1),nrow=length(r)),AIse12no.sens),1,mean,na.rm=T)
avg.ATT12yes.sens<-apply(cbind(matrix(rep(avg.ATT12yes.sens,
    t-1),nrow=length(r)),ATT12yes.sens),1,mean,na.rm=T)
avg.AIse12yes.sens<-apply(cbind(matrix(rep(avg.AIse12yes.sens,
    t-1),nrow=length(r)),AIse12yes.sens),1,mean,na.rm=T)
avg.ATT13no.sens<-apply(cbind(matrix(rep(avg.ATT13no.sens,
    t-1),nrow=length(r)),ATT13no.sens),1,mean,na.rm=T)
avg.AIse13no.sens<-apply(cbind(matrix(rep(avg.AIse13no.sens,
    t-1),nrow=length(r)),AIse13no.sens),1,mean,na.rm=T)
avg.ATT13yes.sens<-apply(cbind(matrix(rep(avg.ATT13yes.sens,
    t-1),nrow=length(r)),ATT13yes.sens),1,mean,na.rm=T)
avg.AIse13yes.sens<-apply(cbind(matrix(rep(avg.AIse13yes.sens,
    t-1),nrow=length(r)),AIse13yes.sens),1,mean,na.rm=T)
avg.tdiff.sens.yes<-apply(cbind(matrix(rep(avg.tdiff.sens.yes,
    t-1),nrow=length(r)),tdiff.sens.yes),1,mean,na.rm=T)
avg.tdiff.sens.no<-apply(cbind(matrix(rep(avg.tdiff.sens.no,
    t-1),nrow=length(r)),tdiff.sens.no),1,mean,na.rm=T)
avg.diff.sens.yes<-apply(cbind(matrix(rep(avg.diff.sens.yes,
    t-1),nrow=length(r)),diff.sens.yes),1,mean,na.rm=T)
avg.diff.sens.no<-apply(cbind(matrix(rep(avg.diff.sens.no,
    t-1),nrow=length(r)),diff.sens.no),1,mean,na.rm=T)

avg.num.yesmsg12.yesvote<-apply(cbind(matrix(rep(avg.num.yesmsg12.yesvote,
    t-1),nrow=length(r)),num.yesmsg12.yesvote),1,mean,na.rm=T)
avg.num.yesmsg12.novote<-apply(cbind(matrix(rep(avg.num.yesmsg12.novote,
    t-1),nrow=length(r)),num.yesmsg12.novote),1,mean,na.rm=T)
avg.num.nomsg.yesvote<-apply(cbind(matrix(rep(avg.num.nomsg.yesvote,
    t-1),nrow=length(r)),num.nomsg.yesvote),1,mean,na.rm=T)
avg.num.nomsg.novote<-apply(cbind(matrix(rep(avg.num.nomsg.novote,
    t-1),nrow=length(r)),num.nomsg.novote),1,mean,na.rm=T)
avg.num.yesmsg13.yesvote<-apply(cbind(matrix(rep(avg.num.yesmsg13.yesvote,
    t-1),nrow=length(r)),num.yesmsg13.yesvote),1,mean,na.rm=T)
avg.num.yesmsg13.novote<-apply(cbind(matrix(rep(avg.num.yesmsg13.novote,
    t-1),nrow=length(r)),num.yesmsg13.novote),1,mean,na.rm=T)
avg.num.both.yesvote<-apply(cbind(matrix(rep(avg.num.both.yesvote,
    t-1),nrow=length(r)),num.both.yesvote),1,mean,na.rm=T)
avg.num.both.novote<-apply(cbind(matrix(rep(avg.num.both.novote,
    t-1),nrow=length(r)),num.both.novote),1,mean,na.rm=T)

}

# Result

result.sens<-data.frame(c(paste(seq(3,1.1,-.1),'$^{-1}$',sep=''),seq(1,3,.1)),
    -1*round(avg.ATT12no.sens,3),round((1-pt(abs(avg.ATT12no.sens/avg.AIse12no.sens),316))*2,3),
    -1*round(avg.ATT13no.sens,3),round((1-pt(abs(avg.ATT13no.sens/avg.AIse13no.sens),316))*2,3),
    round(avg.diff.sens.no,3),round((1-pt(abs(avg.tdiff.sens.no),316))*2,3),
    -1*round(avg.ATT12yes.sens,3),round((1-pt(abs(avg.ATT12yes.sens/avg.AIse12yes.sens),316))*2,3),
    -1*round(avg.ATT13yes.sens,3),round((1-pt(abs(avg.ATT13yes.sens/avg.AIse13yes.sens),316))*2,3),
    round(avg.diff.sens.yes,3),round((1-pt(abs(avg.tdiff.sens.yes),316))*2,3))
names(result.sens)<-c('r','ATT12no','p(ATT12no)','ATT13no','p(ATT13no)','diff.no','p(diff.no)',
    'ATT12yes','p(ATT12yes)','ATT13yes','p(ATT13yes)','diff.yes','p(diff.yes)')

# LaTeX version of table created manually in .tex file, pasting in the following:   
write.table(result.sens,file='sens.txt',sep='&',eol=' \\\\\n',row.names=F,col.names=F,quote=F)

# ====================================================
# Appendix Table 3. Alternative Treatment Placebo Test
# ====================================================

soaps.unmatch1<-multinom(vote.full~TVsoaps,
    data=final.data[final.data$reception %in% c('Yes','No','Both'),])
movie.unmatch1<-multinom(vote.full~TVmovie,
    data=final.data[final.data$reception %in% c('Yes','No','Both'),])
soaps.unmatch1.est<-summary(soaps.unmatch1,cor=F)$coefficients[,2]
soaps.unmatch1.se<-summary(soaps.unmatch1,cor=F)$standard.errors[,2]
movie.unmatch1.est<-summary(movie.unmatch1,cor=F)$coefficients[,2]
movie.unmatch1.se<-summary(movie.unmatch1,cor=F)$standard.errors[,2]

soaps.match1<-multinom(vote.full~TVsoaps,
    data=data.match)
movie.match1<-multinom(vote.full~TVmovie,
    data=data.match)
soaps.match1.est<-summary(soaps.match1,cor=F)$coefficients[,2]
soaps.match1.se<-summary(soaps.match1,cor=F)$standard.errors[,2]
movie.match1.est<-summary(movie.match1,cor=F)$coefficients[,2]
movie.match1.se<-summary(movie.match1,cor=F)$standard.errors[,2]

placebo.est<-as.matrix(rbind(soaps.unmatch1.est, movie.unmatch1.est, soaps.match1.est, movie.match1.est))
placebo.se<-as.matrix(rbind(soaps.unmatch1.se, movie.unmatch1.se, soaps.match1.se, movie.match1.se))

placebo.stars<-matrix('',nrow=nrow(placebo.est),ncol=ncol(placebo.est))
placebo.stars[2*(1-pnorm(abs(placebo.est/placebo.se)))<.1]<-'$\\dagger$'
placebo.stars[2*(1-pnorm(abs(placebo.est/placebo.se)))<.05]<-'*'
placebo.stars[2*(1-pnorm(abs(placebo.est/placebo.se)))<.01]<-'**'
placebo.stars[2*(1-pnorm(abs(placebo.est/placebo.se)))<.001]<-'***'

placebo.spacer<-ifelse(round(placebo.est,2)<0,'','\\ ')

placebo.est<-matrix(paste(placebo.spacer,round(placebo.est,2),placebo.stars,sep=''),nrow=nrow(placebo.est))
placebo.se<-matrix(paste('(',round(placebo.se,2),')',sep=''),nrow=nrow(placebo.se))

placebo.table<-matrix(rbind(as.vector(placebo.est),as.vector(placebo.se)),ncol=ncol(placebo.est))

bottom.note.placebo<-paste('NOTE: Each line reports coefficients and standard errors from a bivariate multinomial logistic regression of vote choice on the covariate plus an intercept (not shown). Reference category is “Yes” vote. N = 1242 pre-matching and 474 post-matching. *$p < .05$.')

match.table.latex<-latex(placebo.table,file='placebo_table.tex',collabel.just=rep('l',8),col.just = rep('l',8),rowname=rep(c('TVsoaps','','TVmovie',''),2),rowlabel='',colheads=c("\nNo","Blank/\nNone","\nNR"),rgroup=c('Pre-matching','Post-matching'),n.rgroup=c(4,4),caption = 'Alternative Treatment Placebo Test',insert.bottom=bottom.note.placebo,booktabs = F, ctable = T, where = "htp",extracolsize="normalsize",cgroup=c('Plebiscite Vote:'),n.cgroup=3)
